/*
 * VerseQuickOptionPane.java
 *
 * Created on 10/07/2013, 02:20:18 PM
 */

package com.simplebible.ui.components;

import java.awt.Component;
import java.util.ArrayList;
import java.util.List;
import javax.swing.BorderFactory;
import javax.swing.JPopupMenu;
import wl.util.TextResourcesUtil;
import com.simplebible.bible.objects.Abreviation;

/**
 *
 * @author Williams Lopez
 */
public class VerseQuickOptionPane extends javax.swing.JPanel {

    JPopupMenu popup;
    Abreviation verse;
    String word;

    List<VerseQuickOptionListener> marcadorListener = new ArrayList<VerseQuickOptionListener>();
    List<VerseQuickOptionListener> notaListener = new ArrayList<VerseQuickOptionListener>();
    List<VerseQuickOptionListener> wordListener = new ArrayList<VerseQuickOptionListener>();
    

    /** Creates new form VerseQuickOptionPane */
    public VerseQuickOptionPane() {
        initComponents();
        try {
            TextResourcesUtil.registrarComponente(this);
        } catch (Exception e) {
        }
    }


    public void show(Abreviation verse,Component inv,int x, int y){
        if(popup == null){
            popup = new JPopupMenu();
            popup.add(this);
            popup.setOpaque(false);
            popup.setBorder(BorderFactory.createEmptyBorder());
            
        }
        this.labelDict.setVisible(false);
        this.verse = verse;
        popup.show(inv, x, y);
    }


    public void show(Abreviation verse,String word,Component inv,int x, int y){
        if(popup == null){
            popup = new JPopupMenu();
            popup.add(this);
            popup.setOpaque(false);
            popup.setBorder(BorderFactory.createEmptyBorder());

        }
        this.labelDict.setVisible(true);
        this.word = word;
        this.verse = verse;
        popup.show(inv, x, y);
    }


    public void addMarcadorListener(VerseQuickOptionListener ac){
        marcadorListener.add(ac);
    }

    public void addNoteListener(VerseQuickOptionListener ac){
        notaListener.add(ac);
    }

    public void addWordListener(VerseQuickOptionListener ac){
        wordListener.add(ac);
    }

    @Override
    public void setVisible(boolean aFlag) {
        popup.setVisible(aFlag);
    }


    private void fireListener(List<VerseQuickOptionListener> listener,Abreviation verse,String command, Object other){
        for(VerseQuickOptionListener v: listener){
            v.action(verse, command, other);
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        labelBookmark = new wl.ui.ButtonLabel();
        labelNote = new wl.ui.ButtonLabel();
        labelDict = new wl.ui.ButtonLabel();

        setBackground(new java.awt.Color(255, 255, 255));
        setMinimumSize(new java.awt.Dimension(100, 50));
        setOpaque(false);
        setPreferredSize(new java.awt.Dimension(130, 50));

        labelBookmark.setIcon(new javax.swing.ImageIcon(getClass().getResource("/simplebible/ui/img/bookmark.png"))); // NOI18N
        labelBookmark.setToolTipText("Agregar versiculo a marcadores");
        labelBookmark.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                labelBookmarkActionPerformed(evt);
            }
        });

        labelNote.setIcon(new javax.swing.ImageIcon(getClass().getResource("/simplebible/ui/img/note_add.png"))); // NOI18N
        labelNote.setToolTipText("Agregar a notas");
        labelNote.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                labelNoteActionPerformed(evt);
            }
        });

        labelDict.setIcon(new javax.swing.ImageIcon(getClass().getResource("/simplebible/ui/img/dictionary.png"))); // NOI18N
        labelDict.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                labelDictActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(labelBookmark, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(labelNote, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(labelDict, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(labelDict, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(labelBookmark, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelNote, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void labelBookmarkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_labelBookmarkActionPerformed
        fireListener(marcadorListener,verse, "addBookmarkSelected", this);
        this.setVisible(false);
    }//GEN-LAST:event_labelBookmarkActionPerformed

    private void labelNoteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_labelNoteActionPerformed
        fireListener(notaListener,verse, "addNoteSelected", this);
        this.setVisible(false);
    }//GEN-LAST:event_labelNoteActionPerformed

    private void labelDictActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_labelDictActionPerformed
        fireListener(wordListener,verse,word,this);
        this.setVisible(false);
    }//GEN-LAST:event_labelDictActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private wl.ui.ButtonLabel labelBookmark;
    private wl.ui.ButtonLabel labelDict;
    private wl.ui.ButtonLabel labelNote;
    // End of variables declaration//GEN-END:variables

}
